package com.zj.common.mq;

import javax.jms.BytesMessage;
import javax.jms.Message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import com.zj.common.TiripPackage;
import com.zj.common.xml.XmlUtil;
import com.zj.service.yb.JhSyJshDz;
import com.zj.service.yb.JhSyYhRqLs;

@Component
public class ReceiveMessage {

	
	@Autowired
	JhSyJshDz jhsyJsDz;

	@Autowired
	JhSyYhRqLs jhSyYhRqLs;

	// 异步接收
	@JmsListener(destination = "SBFSY.EXT.BATCH.IN")
	public void ybMessage(Message message) throws Exception {
		BytesMessage msg = (BytesMessage) message;
		byte[] bs = new byte[(int) msg.getBodyLength()];
		String resp = null;
		while (msg.readBytes(bs) != -1) {
			resp = new String(bs, "GBK");

		}
		System.out.println(resp);
		TiripPackage tiripPackage = XmlUtil.toBean(resp, TiripPackage.class);
		String crId = message.getJMSCorrelationID();
		String serviceId = tiripPackage.getIdentity().getServiceId();
		// 批扣
		if (serviceId.equals("SYPKA1")) {
		}
		// 个人缴费日切流水对账收妥回执
		if (serviceId.equals("SYLSY2")) {
			jhSyYhRqLs.pk(crId, tiripPackage);
			
		}
		// 对账请求
		if (serviceId.equals("SYJSH1")) {
			jhsyJsDz.pk(crId, tiripPackage);
		}
		// 对账请求回执
		if (serviceId.equals("SYJSH4")) {
			jhsyJsDz.pk(crId, tiripPackage);
		}
	}

	// 实时接收
	@JmsListener(destination = "SBFSY.EXT.ONLINE.IN")
	public void ssMessage(Message message) throws Exception {
		BytesMessage msg = (BytesMessage) message;
		byte[] bs = new byte[(int) msg.getBodyLength()];
		String resp = null;
		while (msg.readBytes(bs) != -1) {
			resp = new String(bs, "GBK");

		}
		System.out.println(resp);
		TiripPackage tiripPackage = XmlUtil.toBean(resp, TiripPackage.class);
		String messageId = message.getJMSMessageID();
		String serviceId = tiripPackage.getIdentity().getServiceId();
		// 交易状态查询
		if (serviceId.equals("SYZTC1")) {
		}
		// 实时缴费
		if (serviceId.equals("SYSKA1")) {
		}
	}

}
